package cn.rokhdelar.ams.management.mapper;

import cn.rokhdelar.ams.management.domain.po.SysUser;
import cn.rokhdelar.ams.management.domain.vo.RoleVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

/**
* @author rokhdelar
 * 针对表【sys_user(用户表)】的数据库操作Mapper
* @since 2024-10-02 13:56:45
* cn.rokhdelar.oaaapi.management.domain.po.SysUser
*/
public interface SysUserMapper extends BaseMapper<SysUser> {
    /**
     * 根据用户id查询用户权限
     * @param id 用户id
     * @return 用户权限关键字集合
     */
    @Select("""
            select sa.authority_key from sys_user u
            left join sys_user_role sur on u.id = sur.user_id
            left join sys_role sr on sur.role_id = sr.id
            left join sys_role_authority sra on sur.role_id = sra.role_id
            left join sys_authority sa on sra.authority_id = sa.id
            where u.id =  #{id} and sur.deleted=0 and sr.deleted=0 and sra.deleted=0 and sa.deleted=0 """)
    Collection<String> selectUserAuthoritiesById(String id);

    @Select("""
            select sr.*
            from sys_user u
            join sys_user_role sur on u.id = sur.user_id
            join sys_role sr on sur.role_id = sr.id
            where u.id = #{id} and u.deleted=0 and sur.deleted=0 and sr.deleted=0
            """)
    List<RoleVO> getRoleListByUserId(String id);
}





